package ro.imc.ums.dani.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ro.imc.ums.dani.classes.Professor;
import ro.imc.ums.dani.database.ProfessorCrud;

public class ProfessorInterface {
	

	private JFrame window;
	private JPanel panel;
	private JLabel lFirstName;
	private JLabel lLastName;
	private JLabel lId;
	private JLabel lCnp;
	private JLabel lTitle;
	private JLabel lField;
	private JButton addGrades;
	
	public ProfessorInterface() {
		createInterface();
		createPanel();
		createButtons();
		window.setVisible(true);
	}

	private void createInterface() {
		window = new JFrame();
		window.setTitle("UMS - Professor Interface");
		window.setSize(500, 400);
		window.setLocation(300, 300);
		window.setResizable(false);
		window.setLayout(new BorderLayout());
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	private void createPanel() {
		panel = new JPanel();
		panel.setLayout(null);
		panel.setBackground(Color.WHITE);
		window.add(panel);
	}
	
	private void createButtons(){
		addGrades = new JButton("Add Grades");
		addGrades.setSize(140, 25);
		addGrades.setLocation(270, 100);
		addGrades.setForeground(Color.black);
		addGrades.setBackground(Color.red);
		panel.add(addGrades);
	}
	public void professorInformation(String cnp){
		List<Object> professorsList = new ArrayList<Object>();
		ProfessorCrud  getProfessorsList = new ProfessorCrud();
		professorsList = (ArrayList<Object>)getProfessorsList.selectOne(cnp);
		
		List<Professor> professorListInfo = new ArrayList<Professor>();
		for(Object o : professorsList){
			professorListInfo.add((Professor)o);
		}
		String[] dataInfo = new String[professorListInfo.size()];
		for(int i=0;i<professorListInfo.size();i++){			
			dataInfo[i] = professorListInfo.get(i).getFirstName() + " " + professorListInfo.get(i).getLastName() + "\n";			
		
		
		lFirstName = new JLabel("First Name: " + professorListInfo.get(i).getFirstName());
		lFirstName.setSize(200,20);
		lFirstName.setLocation(40,80);
		
		lLastName = new JLabel("Last Name: " + professorListInfo.get(i).getLastName());
		lLastName.setSize(200,20);
		lLastName.setLocation(40, 120);
		
		lId = new JLabel("Professor Id: " + professorListInfo.get(i).getId());
		lId.setSize(200,20);
		lId.setLocation(40,160);
		
		lCnp = new JLabel("Cnp: " + professorListInfo.get(i).getCnp());
		lCnp.setSize(200, 20);
		lCnp.setLocation(40, 200);
		
		lTitle = new JLabel("Title: " + professorListInfo.get(i).getTitle());
		lTitle.setSize(200,20);
		lTitle.setLocation(40, 240);
		
		lField = new JLabel("Field: " + professorListInfo.get(i).getField());
		lField.setSize(200,20);
		lField.setLocation(40,280);
		
		panel.add(lFirstName);
		panel.add(lLastName);
		panel.add(lId);
		panel.add(lCnp);
		panel.add(lTitle);
		panel.add(lField);
		}
	}
}
